<template>
  <el-container class="main-container">
    <!-- 头部 -->
    <el-header class="header">
      <el-row :gutter="20">
        <el-col :span="12" class="left-header">
          <h2>数据看板</h2>
        </el-col>
        <el-col :span="12" class="right-header">
          <el-dropdown>
            <span class="el-dropdown-link">
              用户操作<i class="el-icon-arrow-down"></i>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item>个人中心</el-dropdown-item>
                <el-dropdown-item>退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-header>

    <!-- 主要内容 -->
    <el-main class="main-content">
      <div class="grid-container">
        <el-row :gutter="20" v-for="(row, i) in 3" :key="i">
          <el-col 
            v-for="(col, j) in 3" 
            :key="j" 
            :span="8"
            class="chart-container"
          >
            <div ref="chartRefs[i*3 + j]" class="chart"></div>
          </el-col>
        </el-row>
      </div>
    </el-main>

    <!-- 底部 -->
    <el-footer class="footer">© 2023 Data Dashboard. All rights reserved.</el-footer>
  </el-container>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

const chartRefs = ref([])

// 初始化图表
onMounted(() => {
  chartRefs.value.forEach((chartEl, index) => {
    const chart = echarts.init(chartEl)
    const option = getChartOption(index) // 根据索引生成不同图表
    chart.setOption(option)
  })
})

function getChartOption(index) {
  // 示例配置，可自定义不同图表类型
  const options = [
    /* 柱状图配置 */,
    /* 折线图配置 */,
    /* 饼图配置 */,
    // ...共9个配置
  ]
  return options[index] || {}
}
</script>

<style scoped>
.main-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  height: 60px;
  background: #409EFF;
  color: white;
  display: flex;
  align-items: center;
}

.left-header {
  display: flex;
  align-items: center;
}

.right-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.main-content {
  flex: 1;
  padding: 20px;
}

.grid-container {
  height: 100%;
}

.chart-container {
  height: 300px; /* 固定每个图表容器高度 */
  margin-bottom: 20px;
}

.chart {
  width: 100%;
  height: 100%;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.footer {
  height: 50px;
  background: #f5f7fa;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666;
}
</style>